package com.wanmait.movie.controller;

import com.wanmait.movie.entity.MovieType;
import com.wanmait.movie.service.MovieTypeService;
import com.wanmait.movie.util.AjaxResult;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("manage/movieType")
public class ManageMovieTypeController {
    @Resource
    private MovieTypeService movieTypeService;

    @GetMapping("list")
    public AjaxResult list(String keyword){
        return AjaxResult.success(movieTypeService.getMovieTypeList(keyword));
    }

    @PostMapping("saveOrUpdate")
    public AjaxResult saveOrUpdate(@RequestBody MovieType movieType){
        if (!movieTypeService.saveOrUpdate(movieType)){
            return AjaxResult.error(505,"电影类型添加或保存失败");
        }
        return AjaxResult.success(movieTypeService.saveOrUpdate(movieType));
    }

    @GetMapping("delete")
    public AjaxResult delete(Integer id){
        if (!movieTypeService.removeById(id)){
            return AjaxResult.error(506,"电影类型删除失败");
        }
        return AjaxResult.success(movieTypeService.removeById(id));
    }
}
